package com.example.demo.service;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.demo.bean.CmsMember;
import com.example.demo.mapper.CmsMemberMapper;

@Service
public class CmsMemberService {
		
	@Autowired
	private CmsMemberMapper memberMapper;
	
	public void insert(CmsMember member) {
		if(member.getId()!=null) {
			memberMapper.insert(member);
			System.out.println("有id");
		}else {
			String id = UUID.randomUUID().toString();
			member.setId(id);
			memberMapper.insert(member);
			System.out.println("无id");
		}
	}
	
	public int deleteById(String id) {
		return memberMapper.deleteByPrimaryKey(id);
	}
	
	public void saveOrUpdate(CmsMember member) {
		if(member.getId()!=null) {
			memberMapper.updateByPrimaryKey(member);
			System.out.println("有id");
		}else {
			String id = UUID.randomUUID().toString();
			member.setId(id);
			memberMapper.updateByPrimaryKey(member);
			System.out.println("无id");
		}
	}
	
	public List<CmsMember> findAll(){
		return memberMapper.selectAll();
	}
	
	public CmsMember selectById(String id) {
		return memberMapper.selectByPrimaryKey(id);
	}
}
